<template>
  <div class="app-container">
    <bread parentPathText="巡查管理" currentPathText="巡查统计报表"/>
    <el-form :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="日期选择">
        <el-date-picker
          v-model="date"
          type="daterange"
          size="mini"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态筛选">
        <el-select
          v-model="queryParams.gridVal"
          placeholder="请选择"
          clearable
          size="small"
          style="width: 260px"
          @change="gridValChange"
        >
          <el-option
            v-for="item in gridData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="巡查区域">
        <el-select
          v-model="queryParams.groupVal"
          placeholder="选择区域"
          clearable
          size="small"
          style="width: 260px"
          @change="areaChange"
        >
          <el-option
            v-for="item in groupData"
            :key="item.id"
            :label="item.communityName"
            :value="item.id"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="筛选类型">
        <el-select
          v-model="queryParams.type"
          placeholder="选择类型"
          clearable
          size="small"
          style="width: 260px"
        >
          <el-option
            v-for="item in types"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="queryParams.info"
          placeholder="请输入姓名/电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableList">
      <el-table-column
        align="center"
        label="巡查员姓名"
        prop="inspectUserName"
        :show-overflow-tooltip="true"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="巡查区域"
        prop="miniGridName"
        :show-overflow-tooltip="true"
        min-width="20%"
      />
      <!-- <el-table-column
        align="center"
        label="详细地址"
        prop="communityUnitName"
        min-width="20%"
      /> -->
      <el-table-column align="center" label="整治前" min-width="30%">
        <template slot-scope="scope">
          <el-image :src="scope.row.beforeImg" class="el-img"></el-image>
        </template>
      </el-table-column>
      <el-table-column align="center" label="整治后" min-width="30%">
        <template slot-scope="scope">
          <el-image :src="scope.row.afterImg" v-if="scope.row.afterImg" class="el-img"></el-image>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="整改状态"
        min-width="15%"
        prop="statusStr"
      />
      <el-table-column
        align="center"
        label="整改人员"
        prop="changeUserName"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="巡查时间"
        prop="createTime"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="操作"
        min-width="25%"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            >查看</el-button
          >
           <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加/编辑弹框 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      append-to-body
    >
    <div class="info-box">
        <div class="item">
          <div class="label-point">点位名称：</div>
          <div>{{detail.miniGridName}}</div>
        </div>
        <div class="item">
          <div>审 批 人 ：</div>
          <div>{{detail.approveUserName}}</div>
        </div>
        <div class="item">
          <div>整治情况：</div>
          <div>{{detail.statusStr}}</div>
        </div>
        <div class="item">
          <div>审批时间：</div>
          <div>{{detail.approveTime}}</div>
        </div>
        <div class="item">
          <div>巡 查 员 ：</div>
          <div>{{detail.inspectUserName}}</div>
        </div>
        <div class="item">
          <div>整改人员：</div>
          <div>{{detail.changeUserName}}</div>
        </div>
        <div class="item" style="margin-bottom:0;">
          <div>
            <el-image :src="detail.beforeImg" class="pop-img"></el-image>
            <div>发布时间：{{detail.createTime}}</div>
          </div>
        </div>
        <div class="item" style="margin-bottom:0;">
          <div>
            <el-image :src="detail.afterImg" class="pop-img"></el-image>
            <div>办结时间：{{detail.completeTime}}</div>
          </div>
        </div>
    </div>
    </el-dialog>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
    >
    </el-pagination>
  </div>
</template>
<script>
import initPagin from '../mixins/index.js';
export default {
  mixins:[initPagin],
  data() {
    return {
      date: "",
      queryParams: {
        gridVal: "",
        groupVal: "",
        type: "",
        info: "",
      },
      gridData: [
        {
          label: "全部",
          value: 0,
        },
        {
          label: "待整改",
          value: 1,
        },
        {
          label: "整改中",
          value: 2,
        },
        {
          label: "已完结",
          value: 3,
        },
      ],
      groupData: [],
      types: [
        {
          label: "全部",
          value: 0,
        },
        {
          label: "姓名",
          value: 1,
        },
        {
          label: "电话",
          value: 2,
        },
      ],
      detail:{
        miniGridName:'',
        approveUserName:'',
        statusStr:'',
        approveTime:'',
        inspectUserName:'',
        changeUserName:'',
        createTime:'',
        completeTime:'',
        beforeImg:'',
        afterImg:''
      },
      loading: false,
      // 弹框
      title: "整改信息",
      dialogVisible: false,
      time: new Date().getTime(),
    };
  },
  mounted() {
    this.getList();
    this.getAreaList();
  },
  methods: {
    // 搜索按钮操作
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
       Object.keys(this.queryParams).forEach((key) => {
            this.queryParams[key] = "";
        });
        this.date = '';
    },
    // 获取小区列表
    getAreaList() {
      let params = {
        time: this.time,
      };
      let result = this.$md5.transferValue(params);
      this.axios
        .post(this.stateUrl.region.selectLists, {
          time: this.time,
          sign: this.$md5.val(result),
        })
        .then((res) => {
          this.groupData = res.data.data;
        })
        .catch(() => {});
    },
    // 获取列表
    getList() {
      let params = {
        time: this.time,
        pageNum:this.pageNum,
        pageSize:this.pageSize,
        inspectStatus: this.queryParams.gridVal,
        startTime: this.date ? this.date[0] : "",
        endTime: this.date ? this.date[1] : "",
        status: this.queryParams.type,
        queryMsg: this.queryParams.info,
        // communityId: this.queryParams.groupVal,
      };
      let result = this.$md5.transferValue(params);
      this.axios
        .post(this.stateUrl.inspect.list, {
          time: this.time,
          pageNum:this.pageNum,
          pageSize:this.pageSize,
          inspectStatus: this.queryParams.gridVal,
          startTime: this.date ? this.date[0] : "",
          endTime: this.date ? this.date[1] : "",
          status: this.queryParams.type,
          queryMsg: this.queryParams.info,
          // communityId: this.queryParams.groupVal,
          sign: this.$md5.val(result),
        })
        .then((res) => {
          this.tableList = res.data.data.list;
          this.total = res.data.data.total;
        })
        .catch(() => {});
    },
    // 详情
    handleUpdate(row) {
      this.dialogVisible = true;
      let params = {
        time:this.time,
        id:row.id
      }
      let result = this.$md5.transferValue(params);
      this.axios.post(this.stateUrl.inspect.inspectDetails,{
        time:this.time,
        id:row.id,
        sign: this.$md5.val(result)
      }).then(res=>{
        this.detail.miniGridName = res.data.data.miniGridName;
        this.detail.approveUserName = res.data.data.approveUserName;
        this.detail.statusStr = res.data.data.statusStr;
        this.detail.approveTime = res.data.data.approveTime;
        this.detail.inspectUserName = res.data.data.inspectUserName;
        this.detail.changeUserName = res.data.data.changeUserName;
        this.detail.beforeImg = res.data.data.beforeImg;
        this.detail.createTime = res.data.data.createTime;
        this.detail.afterImg = res.data.data.afterImg;
        this.detail.completeTime = res.data.data.completeTime;
      }).catch(()=>{})
    },
    // 删除按钮操作
    handleDelete(row) {
      let that = this;
      this.$confirm("是否确认删除?", "提醒", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          that.delRole(row.id);
        })
        .catch(() => {});
    },
    // 删除
    delRole(id) {
      let params = {
        time: this.time,
        id,
      };
      let result = this.$md5.transferValue(params);
      this.axios
        .post(this.stateUrl.inspect.delete, {
          time: this.time,
          id,
          sign: this.$md5.val(result),
        })
        .then((res) => {
          this.msgSuccess("删除成功");
          this.getList();
        })
        .catch(() => {});
    },
    // 状态筛选
    gridValChange(val) {
      this.queryParams.gridVal = val;
    },
    // 选择小区
    areaChange(val) {
      this.queryParams.groupVal = val;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style lang="less" scoped>
.el-img {
  width: 50px;
  height: 50px;
}
.info-box{
  display: flex;
  flex-wrap: wrap;
  .item{
    display: flex;
    width:50%;
    margin-bottom:30px;
  }
}
.pop-img{
  width:251px;
  height:251px;
  margin-bottom: 15px;
}
.label-point{
  width:80px;
}
</style>